package com.swl.controller;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.*;

@RestController
public class FileController {
    @RequestMapping("/lunbo/add")
    public Map<String, Object> uploadMethod(MultipartFile file) {
        System.out.println("--------");
        String oldName = file.getOriginalFilename();
        String newName = UUID.randomUUID().toString() + oldName.substring(oldName.lastIndexOf("."));
        System.out.println(newName);
        File pic = new File("D:/upload/" + newName);
        Map map = new HashMap<String, Object>();
        try {
            file.transferTo(pic);
            map.put("msg","ok");
            map.put("code",200);
            map.put("src", newName);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return map;
    }
}
